﻿namespace Admin.Crypto
{
    /// <summary>
    /// 启动程序
    /// </summary>
    public class Program
    {
        /// <summary>
        /// 程序启动入口
        /// </summary>
        /// <param name="args">入口参数</param>
        public static void Main(string[] args)
        {            
            CreateHostBuilder(args)
                .Build()               
                .Run();
        }      

        /// <summary>
        /// Host Builder
        /// </summary>
        /// <param name="args">传入参数</param>
        /// <returns></returns>
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            var dto = CommandUtils.GetEnvPort(CommandUtils.ParseArgs(args));
            var env = dto.Env;

            return Host.CreateDefaultBuilder(args)                       
                 .ConfigureLogging(builder =>
                 {                     
                     var log4netConfig = "log4net.config";
                     Console.WriteLine("当前使用的log4net配置文件 ：" + log4netConfig);
                     builder.AddLog4Net($"config/{log4netConfig}"); ;
                 })
                 .ConfigureWebHostDefaults(webBuilder =>
                 {
                     webBuilder.UseStartup<Startup>();
                     webBuilder.UseUrls($"http://*:{dto.Port}");
                 });
        }
    }
}
